24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 const double EPS
= 1e-9;
29 int cmp(double x
, double y
= 0, double tol
= EPS
) {
30 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
36 vector
<int> A
[2 * MAXN
], B
[2 * MAXN
];
41 for (int i
= 0; i
< n
; ++i
) {
42 for (int j
= 0; j
< n
; ++j
) {
43 scanf("%d", &mat
[i
][j
]);
47 for (int k
= 0; k
< n
; ++k
) {
48 int i
= n
- k
- 1, j
= 0;
50 while (i
< n
and j
< n
) {
51 A
[k
].push_back(mat
[i
][j
] + A
[k
].back());
56 for (int k
= 1; k
< n
; ++k
) {
58 A
[n
- 1 + k
].push_back(0);
59 while (i
< n
and j
< n
) {
60 A
[n
- 1 + k
].push_back(mat
[i
][j
] + A
[n
- 1 + k
].back());
65 for (int k
= 0; k
< n
; ++k
) {
68 while (i
< n
and j
>= 0) {
69 B
[k
].push_back(mat
[i
][j
] + B
[k
].back());
74 for (int k
= 1; k
< n
; ++k
) {
76 B
[n
- 1 + k
].push_back(0);
77 while (i
< n
and j
>= 0) {
78 B
[n
- 1 + k
].push_back(mat
[i
][j
] + B
[n
- 1 + k
].back());
83 // For(k, 0, 2 * n - 1) {
84 // printf("A[k=%d]: ", k);
85 // For(i, 0, A[k].size()) printf("%d ", A[k][i]);
88 // For(k, 0, 2 * n - 1) {
89 // printf("B[k=%d]: ", k);
90 // For(i, 0, B[k].size()) printf("%d ", B[k][i]);
97 for (int i
= 0; i
< n
; ++i
) {
98 for (int j
= 0; j
< n
; ++j
) {
99 for (int delta
= 0; i
+ delta
< n
and j
+ delta
< n
; ++delta
) {
100 int ka
= n
- 1 - i
+ j
;
101 int kb
= i
+ j
+ delta
;
103 int sumA
= A
[ka
].at( min(i
, j
) + delta
+ 1 ) - A
[ka
].at( min(i
, j
) );
104 int sumB
= B
[kb
].at( min(i
, n
- 1 - j
- delta
) + delta
+ 1 ) - B
[kb
].at( min(i
, n
- 1 - j
- delta
) );
106 if (sumA
- sumB
> ans
) {
107 //printf("new best sum from [%d, %d] and delta = %d, (sumA = %d, sumB = %d, i + delta =%d, j + delta = %d)\n", i, j, delta, sumA, sumB, i + delta, j + delta);